/**
 * Project:TODO ADD PROJECT NAME
 * Modify Information:
 * ================================================================
 * Author         Date           Description
 * ------------   ----------      --------------------------------
 * songyf        2023/4/19         TODO:
 * ================================================================
 * Copyright (c) 银联商务股份有限公司 www.chinaums.com
 */
package language.rmi.complex.client;


import language.rmi.complex.stub.Compute;

import java.math.BigDecimal;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class Client {
    public static void main(String args[]) {
        System.setProperty("java.security.policy", Client.class.getClassLoader().getResource("java.policy").getFile());
        SecurityManager securityManager = new SecurityManager();
        System.setSecurityManager(securityManager);
        try {
            String name = "Compute";
            Registry registry = LocateRegistry.getRegistry(1199);
            Compute comp = (Compute) registry.lookup(name); //拿到远程的对象，是个代理
            Pi task = new Pi(5);
            BigDecimal pi = comp.executeTask(task);//客户端需要实例化Pi传给服务端
            System.out.println(pi);
        } catch (Exception e) {
            System.err.println("Client exception:");
            e.printStackTrace();
        }
    }
}